﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml.Linq;
namespace Shorten.Core.Providers
{
    public class SettingsManagement
    {
        private static XDocument SettingsFile
        {
            get { return XDocument.Load(HttpContext.Current.Server.MapPath("~/App_Data/Settings.xml")); }
        }

        public static string GetSiteName()
        {
            return SettingsFile.Descendants("Settings").Select(f => (string)f.Element("SiteName")).SingleOrDefault();
        }

        public static string GetSiteTheme()
        {
            return SettingsFile.Descendants("Settings").Select(f => (string)f.Element("SiteTheme")).SingleOrDefault();
        }

        public static int GetSiteURLLength()
        {
            try
            {
                return int.Parse(SettingsFile.Descendants("Settings").Select(f => (string)f.Element("SiteURLLength")).SingleOrDefault());
            }
            catch
            {
                return 4;
            }
        }
    }
}
